import {
  ENERGY_CONSUMPTION_STRUCTURE_TABLE,
  ENERGY_CONSUMPTION_STRUCTURE_SUB_TABLE,
  TABLE_OF_COMPREHENSIVE_ENERGY_CONSUMPTION_PER_UNIT_PRODUCT,
  ENTERPRISE_BASIC_INFORMATION_TABLE_ID,
  PROGRESS_ENERGY_SAVING_TARGET_COMPLETION_TABLE,
  ENERGY_SAVING_RENOVATION_PROJECT_INFORMATION_TABLE,
  REPORT_REPORT,
} from '@/config'
import { getTabsOfTenantId } from '@/api/reportReview'

export default {
  data () {
    return {
      myIds: []
    }
  },
  computed: {
    tableList () {
      const prefix = this.isYear ? '年' : '季';
      const ids = this.isYear
        ? [
          ENTERPRISE_BASIC_INFORMATION_TABLE_ID,
          ENERGY_CONSUMPTION_STRUCTURE_TABLE.ID,
          ENERGY_CONSUMPTION_STRUCTURE_SUB_TABLE.ID,
          TABLE_OF_COMPREHENSIVE_ENERGY_CONSUMPTION_PER_UNIT_PRODUCT.ID,
          PROGRESS_ENERGY_SAVING_TARGET_COMPLETION_TABLE.ID,
          ENERGY_SAVING_RENOVATION_PROJECT_INFORMATION_TABLE.ID
        ]
        : [
          ENERGY_CONSUMPTION_STRUCTURE_TABLE.ID,
          ENERGY_CONSUMPTION_STRUCTURE_SUB_TABLE.ID,
          TABLE_OF_COMPREHENSIVE_ENERGY_CONSUMPTION_PER_UNIT_PRODUCT.ID,
        ]
      return ids.map(id => ({
        id: id,
        name: prefix + REPORT_REPORT[id].alias
      }))
    },
    myTabs () {
      return this.myIds.reduce((acc, vv) => {
        const target = this.tableList.find(v => v.id === vv)
        target && acc.push(target);
        return acc;
      }, [])
    },
  },
  methods: {
    async queryTabs (enterpriseId, year, quarter) {
      try {
        const { data } = await getTabsOfTenantId(enterpriseId, year, quarter);
        this.myIds = data || [];
      } catch (e) {}
    }
  },
}
